public class Day2 {

    public static int removeDuplicates (int[] nums) {

        int curNumIndex = 0;
        int unnecessaryIndex = 1;
        int len = 1;
        for (int i = 1; i < nums.length; i++) {

            if (nums[unnecessaryIndex] > nums[curNumIndex]) {

                len++;
                curNumIndex++;
                unnecessaryIndex++;

            } else {

                if (nums[i] > nums[unnecessaryIndex]) {

                    nums[curNumIndex + 1] = nums[i];
                    len++;
                    unnecessaryIndex = i;
                    curNumIndex++;
                }

            }

        }

        return len;

    }

    public static void main(String[] args) {

        System.out.println(removeDuplicates(new int[]{0,0,1,1,1,2,2,3,3,4}));
        System.out.println(removeDuplicates(new int[]{0,0,1,1,1,2,2,3,3,4,5,6,7,8,8,9,9}));

//        System.out.println(truncateSentence("Sup motherfucker hell ya kuc your ass", 4));

    }

    public static String truncateSentence (String s, int k) {

        String[] strings = s.split(" ");

        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < k - 1; i++) {
            stringBuilder.append(strings[i] + " ");
        }
        stringBuilder.append(strings[k - 1]);

        return stringBuilder.toString();
    }

}
